package com.meila.cms.controller;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.meila.cms.auth.AuthClass;
import com.meila.cms.entity.AjaxObj;
import com.meila.cms.model.PartsModel;
import com.meila.cms.services.IDrawingService;
import com.meila.cms.util.json.JsonUtil2;
import com.meila.cms.util.page.Pager;

@Controller
@RequestMapping("/after/drawing")
@AuthClass("login")
public class DrawingController {
	
	private IDrawingService partsService;
 
	public IDrawingService getPartsService() {
		return partsService;
	}
	
	@Inject
	public void setPartsService(IDrawingService partsService) {
		this.partsService = partsService;
	}

	/**
	 * 获取零件分页列表集合信息
	 * 
	 * @param model
	 * @return 获取零件分页列表集合信息
	 */
	@RequestMapping(value="/drawing_list", method = RequestMethod.GET)
	public String listParts(PartsModel partsModel,Model model) {
		 
		// 获取用户分页列表集合信息
		Pager<PartsModel> listParts = partsService.findParts(partsModel);
		// 保存用户分页列表集合信息
		model.addAttribute("datas", listParts);
		
		model.addAttribute("jsondatas",JsonUtil2.toJSONList(listParts.getDatas()));
		
		return "drawing/drawing_list";
	}
	
	@RequestMapping(value="/drawing_list", method = RequestMethod.POST)
	@ResponseBody
	public List listParts(PartsModel partsModel) {
		 
		// 获取用户分页列表集合信息
		Pager<PartsModel> listParts = partsService.findParts(partsModel);

		
		return listParts.getDatas();
	}
	
	/**
	 * 更新字段
	 * @param userModel
	 * @return
	 */
	@RequestMapping("/update")
	public String update(PartsModel partsModel) {
 
	    partsService.update(partsModel);
		
		return "redirect:/after/drawing/drawing_list";
	}

	
	/**
	 * 上下架
	 * @param userModel
	 * @return
	 */
	@RequestMapping("/updateStatus")
	@ResponseBody
	public AjaxObj updateStatus(PartsModel partsModel) {
 
		AjaxObj  ajaxObj=partsService.update(partsModel);
		
		return ajaxObj;
	}

}
